package com.zhang.servicemap.remote;

import com.zhang.internalcommon.constant.AmapConfigConstant;
import com.zhang.internalcommon.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 类功能描述
 * 获取行政区域信息
 *
 * @author Kye
 * @date 2025-04-11
 */
@Service
public class MapDicDistrictClient {
	@Value("${amap.key}")
	private String amapKey;

	@Autowired
	RestTemplate restTemplate;

	/**
	 * 拼装行政区域获取url
	 *
	 * @param keywords 用户key
	 * @return
	 */
	public String dicDistrict(String keywords) {
		// 拼装请求的url
		StringBuilder url = new StringBuilder();
		url.append(AmapConfigConstant.DISTRICT_URL);
		url.append("?");
		url.append("keywords=" + keywords);
		url.append("&");
		url.append("subdistrict=3");
		url.append("&");
		url.append("key=" + amapKey);

		ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);
		return forEntity.getBody();
	}
}
